export default {
    /**
     * 动态加载外部js
     * @param src 
     */
    loadScript(src: string) {
        return new Promise((res) => {
            const script = document.createElement('script');
            script.type = 'text/javascript';
            script.charset = 'utf-8';
            script.src = src;
            script.onload = res;
            document.head.appendChild(script);
        });
    },
    /**
     * 获取距离顶部高度
     * @param dom dom节点
     * @requires 高度
     */
    getOffsetTop(dom: HTMLElement) {
        let offsetTop = dom.offsetTop;
        while (dom.offsetParent) {
            dom = dom.offsetParent as HTMLElement;
            offsetTop += dom.offsetTop;
        }
        return offsetTop;
    }
}
